<h2 class="template"><%=h "#{l(:issue_template)}" %></h2>
<% if @project.trackers.blank? %>
    <div class="nodata">
      <%= simple_format(l(:text_no_tracker_enabled)) %>
    </div>
<% end %>
<div class="contextual">
  <%= link_to_if_authorized(l(:label_new_templates),
    {:controller => 'issue_templates', :action => 'new', :project_id => @project}, 
    :class => 'icon icon-add') %>
</div>

<% if @notice -%>
  <div class="flash notice"><%= @notice -%></div>
<% end -%>


<% if @template_map.empty? %>
    <div class="template_box">
      <%= l(:no_issue_templates_for_this_project) %>
    </div>
<% end %>

<% @template_map.each_key do |tracker| %>
<div class="template_box">
<h3 class="template_tracker"><%= tracker.name %></h3>
  <%= non_project_tracker_msg(is_project_tracker(tracker.id, @project)) %>

<table class="list issues">
  <thead>
    <tr>
      <th>#</th> 
      <th><%= l(:issue_template_name) %></th>
      <th><%= l(:field_tracker) %></th>
      <th><%= l(:field_author) %></th> 
      <th><%= l(:field_updated_on) %></th>
      <th><%= l(:field_is_default) %></th>
      <th><%= l(:label_enabled) %></th>
       <% if authorize_for("issue_templates", "edit") %>
      <th><%=l(:button_sort)%></th>
      <% end %>
    </tr>
  </thead>
  <tbody>
    <% @template_map[tracker].each do |issue_template| %>
      <tr class="<%= cycle("odd", "even") %> issue_template issue">
        <td><%= link_to h(issue_template.id),  {:controller => 'issue_templates', 
                 :action => 'show', :id => issue_template.id, :project_id => @project}, {:title => issue_template.note } %></td>
        <td><%= link_to h(issue_template.title), {:controller => 'issue_templates', 
                 :action => 'show', :id => issue_template.id, :project_id => @project}, {:title => issue_template.title }, class: "tooltip" %></td>
        <td><%=h issue_template.tracker.name %></td>
        <td><%=h issue_template.author %></td>
        <td><%= format_time(issue_template.updated_on)%> </td>
        <td class="center"><%= checked_image issue_template.is_default? %></td>
        <td class="center"><%= checked_image issue_template.enabled? %></td>

        <% if authorize_for("issue_templates", "edit") %>
        <td>
          <%= issue_template.first? ? '': 
            link_to(image_tag('2uparrow.png', :alt => l(:label_sort_highest)), 
          {:action => :move, :id => issue_template, :to => :to_top}, 
          {:title => l(:label_sort_highest)}) %>
          <%= issue_template.first? ? '': 
            link_to(image_tag('1uparrow.png',   :alt => l(:label_sort_higher)), 
          {:action => :move, :id => issue_template, :to => :higher},
          {:title => l(:label_sort_higher)})  %>
          <%= issue_template.last? ? '': 
            link_to(image_tag('1downarrow.png', :alt => l(:label_sort_lower)), 
          {:action => :move, :id => issue_template, :to => :lower},
          {:title => l(:label_sort_lower)}) %>
          <%= issue_template.last? ? '': 
            link_to(image_tag('2downarrow.png', :alt => l(:label_sort_lowest)), 
          {:action => :move, :id => issue_template, :to => :to_bottom},
          {:title => l(:label_sort_lowest)}) %>
        </td>
      <% end %>
      </tr>
    <% end %>
  </tbody>
</table>
</div>
<% end %>


<% unless @inherit_templates.blank? %>
<h2 class="template"><%=h "#{l(:label_inherited_templates)}" %></h2>
  <div class="template_box">

        <table class="list issues">
          <thead>
          <tr>
            <th>#</th>
            <th><%= l(:issue_template_name) %></th>
            <th><%= l(:field_tracker) %></th>
            <th><%= l(:field_author) %></th>
            <th><%= l(:field_updated_on) %></th>
            <th><%= l(:field_is_default) %></th>
            <th><%= l(:label_enabled) %></th>
          </tr>
          </thead>
          <tbody>
          <% @inherit_templates.each do |issue_template| %>
              <tr class="<%= cycle("odd", "even") %> issue_template issue">
                <td><%= link_to h(issue_template.id),  {:controller => 'issue_templates',
                      :action => 'show', :id => issue_template.id,
                      :project_id => issue_template.project_id }, {:title => issue_template.note } %></td>

                <td><%= link_to h(issue_template.title),  {:controller => 'issue_templates',
                      :action => 'show', :id => issue_template.id,
                      :project_id => issue_template.project_id }, {:title => issue_template.title }, class: "tooltip" %></td>td>
                <td><%=h issue_template.tracker.name %></td>
                <td><%=h issue_template.author %></td>
                <td><%= format_time(issue_template.updated_on)%> </td>
                <td class="center"><%= checked_image issue_template.is_default? %></td>
                <td class="center"><%= checked_image issue_template.enabled? %></td>
              </tr>
          <% end %>
          </tbody>
        </table>
    </div>
 <% end %>

<% unless  @globalIssueTemplates.blank? %>
    <h2 class="template"><%=h "#{l(:global_issue_templates)}" %></h2>
    <div class="template_box">

      <%= l(:only_admin_can_associate_global_template) %>
      <table class="list issues">
        <thead>
        <tr>
          <th>#</th>
          <th><%= l(:issue_template_name) %></th>
          <th><%= l(:field_tracker) %></th>
          <th><%= l(:field_author) %></th>
          <th><%= l(:field_updated_on) %></th>
        </tr>
        </thead>
        <tbody>
        <% @globalIssueTemplates.each do |issue_template| %>
            <tr class="<%= cycle("odd", "even") %> issue_template issue">
              <td>
                <% if User.current.admin? %>
                     <%= link_to h(issue_template.id),  {:controller => 'global_issue_templates',
                                                      :action => 'show', :id => issue_template.id,
                                                      }, {:title => issue_template.note } %>
                <% else %>
                    <%=h issue_template.id %>
                <% end %>
               </td>

              <td>
                <%= link_to h(issue_template.title), {:controller => 'global_issue_templates',
                                                      :action => 'show', :id => issue_template.id,
                                                      }, {:title => issue_template.note }, class: "tooltip" %>
              </td>
              <td><%=h issue_template.tracker.name %></td>
              <td><%=h issue_template.author %></td>
              <td><%= format_time(issue_template.updated_on)%> </td>
            </tr>
        <% end %>
        </tbody>
      </table>

    </div>
<% end %>